﻿# coding:utf-8
from django.http import HttpResponseRedirect,HttpResponse
from django.shortcuts import render_to_response
from django.template.loader import render_to_string

from blog.models import *
from blog.utils import *

def index(request):
    return render_to_response('mblog/index.html')

@master_required
@expose()
def add_mblog(request):
    if request.method == 'POST':
        content = request.POST.get('content') 
        if not content or len(content) > 200:
            return dict(success=False,msg='内容不能为空')

        mb = MBlog(user=request.master,content=content,pub_date = _cntime())
        mb.put()

        return dict(success=True,redirect='/%s/mblog' % request.master.name )
        
@master_required
@expose()
def del_mblog(request):
    if request.method == 'POST':
        id = request.POST.get('id')
        mb = MBlog.get_by_key_name(int(id))
        if not mb:
            return dict(success=False,msg='无此条记录')


